package es.mgil.bluetoothtest;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class BluetoothTestActivity extends Activity {
	private Button btActivate;
	private Button btDeactivate;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.bluetooth_test_layout);

		btActivate = (Button) findViewById(R.id.btActivate);
		btDeactivate = (Button) findViewById(R.id.btDeactivate);

		btActivate
				.setEnabled(!BluetoothAdapter.getDefaultAdapter().isEnabled());
		btDeactivate.setEnabled(BluetoothAdapter.getDefaultAdapter()
				.isEnabled());
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.bluetooth_test_layout, menu);
		return true;
	}

	public void stateClick(View view) {
		String state = "";
		switch (BluetoothAdapter.getDefaultAdapter().getState()) {
		case BluetoothAdapter.STATE_ON:
			state = "Activado";
			break;
		case BluetoothAdapter.STATE_OFF:
			state = "Desactivado";
			break;
		}

		Toast.makeText(this, state, Toast.LENGTH_SHORT).show();
	}

	public void activateClick(View view) {
		BluetoothAdapter.getDefaultAdapter().enable();
		btActivate.setEnabled(false);
		btDeactivate.setEnabled(true);
		Toast.makeText(this, "Bluetooth activado", Toast.LENGTH_SHORT).show();
	}

	public void deactivateClick(View view) {
		BluetoothAdapter.getDefaultAdapter().disable();
		btActivate.setEnabled(true);
		btDeactivate.setEnabled(false);
		Toast.makeText(this, "Bluetooth desactivado", Toast.LENGTH_SHORT)
				.show();
	}

	public void nameClick(View view) {
		String name = BluetoothAdapter.getDefaultAdapter().getName();
		Toast.makeText(this, name, Toast.LENGTH_SHORT).show();
	}

	public void addressClick(View view) {
		String address = BluetoothAdapter.getDefaultAdapter().getAddress();
		Toast.makeText(this, address, Toast.LENGTH_SHORT).show();
	}
}
